<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions"
      xmlns:fmt="http://java.sun.com/jsp/jstl/fmt">
<head>
    <meta charset="UTF-8">
    <title>DECP后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/admin/css/common.css" />
    <link rel="stylesheet" href="/layui/css/layui.css" />
    <style>
        .user-info-head{
            width: 70px;
            height: 70px;
            line-height: 70px;
            position: relative;
            display: inline-block;
            border: 2px solid #eee;
            border-radius: 50%;
            overflow: hidden;
            cursor: pointer;
            margin: 0 auto;
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form user-info-form layui-text" style="max-width: 400px;padding-top: 25px;">
        <div class="layui-form-item layui-upload">
            <label class="layui-form-label">用户头像:</label>
            <div class="user-info-head layui-upload-list" id="userInfoHead">
                <img src="../../admin/images/headless.jpg" id="avatarPath" width="75px" height="75px" alt="">
                <p id="demoText"></p>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名:</label>
            <div class="layui-input-block">
                <input type="text" name="userName" value="" class="layui-input" lay-verify="required"
                       required="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户密码:</label>
            <div class="layui-input-block">
                <input type="password" name="password" value="" class="layui-input" lay-verify="pass" required="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码:</label>
            <div class="layui-input-block">
                <input type="password" name="respass" placeholder="" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系电话:</label>
            <div class="layui-input-block">
                <input type="text" name="phone" value="" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系地址:</label>
            <div class="layui-input-block">
                <textarea type="text" name="address" value=""   class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮政编号:</label>
            <div class="layui-input-block">
                <input type="text" name="zipCode" value="" class="layui-input" >
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
</body>

<script src="/layui/layui.js"></script>
<script>
    layui.use(['form', 'layedit', 'laydate','upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , $ = layui.jquery
            ,upload = layui.upload;


        form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位']
        });


        //监听提交
        form.on('submit(user-save)', function (data) {
            console.log("data---------"+data);
            $.post('trackUser/relogin', data.field, function (data1) {
                console.log("data111111111---------"+data1);
                if (data == "success") {
                    parent.layer.close(top.layerFrameConfig.iframeUserModify.layer_index);
                    parent.layer.msg("添加成功 ！")
                } else {
                    /*layer.alert("添加失败 ！")*/
                    parent.layer.close(top.layerFrameConfig.iframeUserModify.layer_index);
                    parent.layer.msg("添加失败 ！")
                }
            });
            return false;
        });

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#avatarPath'
            ,url: 'api/user/uploadImpage' //改成您自己的上传接口
            ,accept: 'file'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#avatarPath').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });


    });
</script>
</html>